`
https://leetcode.cn/problems/maximum-subarray/
`

/**
 * @param {number[]} nums
 * @return {number}
 */
var maxSubArray = function (nums) {
  const n = nums.length
  let dp_0 = nums[0]
  let dp_1 = 0
  let res = dp_0

  for (let i = 1; i < n; i++) {
    // dp[i] = Math.max(nums[i], nums[i] + dp[i-1])
    dp_1 = Math.max(nums[i], nums[i] + dp_0)
    dp_0 = dp_1
    // 顺便计算最大的结果
    res = Math.max(res, dp_1)
  }

  return res
};